package com.njy.config;

import com.njy.decorator.AsyncDecorator;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import javax.annotation.Resource;
import java.util.Date;
import java.util.concurrent.ScheduledFuture;

/**
 * 实现ThreadPoolTaskScheduler方法重写execute等方法
 */
public class MdcThreadPoolTaskScheduler extends ThreadPoolTaskScheduler {
    @Resource
    private AsyncDecorator asyncDecorator;
    @Override
    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
        return super.scheduleWithFixedDelay(asyncDecorator.decorate(task), startTime, delay);
    }

    @Override
    public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
        return super.schedule(asyncDecorator.decorate(task), startTime);
    }

    @Override
    public void execute(Runnable task) {
        super.execute(asyncDecorator.decorate(task));
    }

    @Override
    public void execute(Runnable task, long startTimeout) {
        super.execute(asyncDecorator.decorate(task), startTimeout);
    }
}
